package com.example.testproj.lrucache;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.testproj.R;
import com.example.testproj.base.MyApplication;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @des:
 * @author: 芮勤
 * @date: 2019/8/9 09:21
 * @see {@link }
 */
public class ImageRecyclerViewAdapter extends RecyclerView.Adapter<ImageRecyclerViewAdapter.MyViewHolder> {
    private static final String TAG = "ImageRecyclerViewAdapte";

    private static String URL = "https://cn.bing.com/cnhp/coverstory?d=";
    private static String START_DATE_STRING = "20140501";
    private static String DATE_FORMAT = "yyyyMMdd";
    private static SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
    private static long startDateLong;

    private Context mContext;

    public ImageRecyclerViewAdapter(Context context) {

        mContext = context;

        try {
            startDateLong = mSimpleDateFormat.parse(START_DATE_STRING).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view= LayoutInflater.from(mContext).inflate(R.layout.item_imageview,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Log.d(TAG, "onBindViewHolder: " + position + "=====" + getCurrentStringDate(position));
//        ((ImageView)holder.itemView).setImageBitmap(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher));
        ImageGetUtils.getInstance().loadImage(R.drawable.test1080, holder.imageView);
        //     ((ImageView)holder.itemView).setImageBitmap(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.test1080));
    }


    @Override
    public int getItemCount() {
        return (int) ((System.currentTimeMillis()-startDateLong)/(24*60*60*1000));
      //  return 20;
    }

    private String getCurrentStringDate(int pos) {
        long time = startDateLong + (24 * 60 * 60 * 1000L) * pos;
        return mSimpleDateFormat.format(new Date(time));
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.imageview);
        }
    }
}
